<?php

class Front_Form_Register extends Zend_Form
{

    public function  __construct($options = null)
    {
		$this->setMethod('Post');
       
		parent::__construct($options);
		
		$login = new Zend_Form_Element_Text("login", array('size' => 25));
		$loginDoesntExist = new Zend_Validate_Db_NoRecordExists('membres', 'login');
		$login ->setLabel('Login *')
		  ->addFilter('StripTags')
		  ->addFilter('StringTrim')
		  ->addValidator('NotEmpty')
		  ->addValidator($loginDoesntExist)
		  ->addValidator('StringLength', false, 3, 20)
		  ->setDescription("");
		
		$emailDoesntExist = new Zend_Validate_Db_NoRecordExists('membres', 'email');
		$email = new Zend_Form_Element_Text("email", array('size' => 25));
		$email ->setLabel('adresse mail *')
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator('NotEmpty')
		->addValidator($emailDoesntExist)
		->addValidator('EmailAddress')
		->setDescription("");
		
		$password = new Zend_Form_Element_Password("password", array('size' => 25));
		$password ->setLabel('mot de passe *')
		->addFilter('StringTrim')
		->addValidator('NotEmpty');
		
		$repassword = new Zend_Form_Element_Password("repassword", array('size' => 25));
		$repassword ->setLabel('Resaisissez le mot de passe *')
		->addFilter('StringTrim')
		->addValidator('NotEmpty');
		$repassword->setDescription("");
		
		$locale = Zend_Registry::get('Zend_Locale');
		//$countries = Zend_Locale::getTranslationList('territory', $locale, 2);
		//->addMultiOptions(Zend_Locale::getCountryTranslationList(Zend_Registry::get('Zend_Locale')))
		$pays = new  Zend_Form_Element_Select("pays");
		$pays ->setLabel('Pays')
		->addMultiOptions(Zend_Locale::getTranslationList('territory', $locale, 2))
		->addValidator('NotEmpty');

				
		$pubKey = '6Lfc-9gSAAAAAAcG5wv0k6SNh96XD4YAtAO5WLqd ';
		$privKey = '6Lfc-9gSAAAAAEGXzka3d1EScKJbtNu0ZjF1KnGG ';
		$recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
		
		$adapter = new Zend_Captcha_ReCaptcha();
		$adapter->setService($recaptcha);
		
		$captcha = new Zend_Form_Element_Captcha('recaptcha', array( 'label' => "Captcha", 'captcha' => $adapter));
		$captcha->removeDecorator('label')->removeDecorator('errors');
		
		
		$this->addElements(array($login, $email, $password, $repassword, $pays, $captcha));
		
		$this->setDecorators( array( array('ViewScript', array('viewScript' => 'count/register-Form.phtml'))));
		
	}
	
	public function isValid($data)
	{
		$password = $this->getElement('password');
// 		$password->addValidator(new Zend_Validate_PasswordMatch($data['repassword']));
	
		return parent::isValid($data);;
	}


}

